import type { RouteRecordRaw } from 'vue-router'

// 系统配置
export interface SystemConfig {
  title: string
  version: string
  tenantEnabled: boolean
  apiBaseUrl: string
  apiTimeout: number
  uploadSizeLimit: number
  cacheEnabled: boolean
  cacheExpire: number
}

// 用户设置
export interface UserSettings {
  theme: 'light' | 'dark' | 'auto'
  language: 'zh-CN' | 'en-US'
  sidebarCollapsed: boolean
  showBreadcrumb: boolean
  showTabs: boolean
  fixedHeader: boolean
}

// 路由元信息
export interface RouteMeta {
  title: string
  icon?: string
  roles?: string[]
  permissions?: string[]
  keepAlive?: boolean
  hidden?: boolean
  noCache?: boolean
  affix?: boolean
  breadcrumb?: boolean
  activeMenu?: string
  externalLink?: string
}

// 应用路由类型
export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> {
  meta?: RouteMeta
  children?: AppRouteRecordRaw[]
}

// 面包屑项
export interface BreadcrumbItem {
  title: string
  path?: string
  icon?: string
}

// 标签页项
export interface TabItem {
  title: string
  name: string
  path: string
  closable: boolean
  affix: boolean
}

// 菜单项
export interface MenuOption {
  key: string
  label: string
  icon?: string
  path?: string
  children?: MenuOption[]
  disabled?: boolean
  hidden?: boolean
}

// 权限检查结果
export interface PermissionResult {
  hasPermission: boolean
  permissions: string[]
  roles: string[]
}

// 数据权限范围
export type DataScopeType = 'ALL' | 'DEPT' | 'DEPT_AND_CHILD' | 'SELF' | 'CUSTOM'

// 数据权限上下文
export interface DataScopeContext {
  userId: string
  tenantId: string
  scopeType: DataScopeType
  deptIds?: string[]
  customScope?: Record<string, any>
}

// 操作日志
export interface OperationLog {
  id: string
  module: string
  operation: string
  method: string
  params?: string
  result?: string
  duration: number
  ip: string
  userAgent?: string
  userId: string
  username: string
  createTime: string
}

// 登录日志
export interface LoginLog {
  id: string
  username: string
  ip: string
  location?: string
  userAgent?: string
  status: 'SUCCESS' | 'FAILURE'
  message?: string
  createTime: string
}

// 会话信息（匹配后端SessionInfo）
export interface OnlineUser {
  sessionId: string
  userId: string
  tenantId?: string
  loginType?: string
  clientIp?: string
  userAgent?: string
  deviceInfo?: string
  createTime?: string
  lastActiveTime?: string
  tokenTimeout?: number
  // 前端扩展字段
  username?: string
  nickname?: string
  sessionActive?: boolean
}

// 在线用户详细信息
export interface OnlineUserDetail {
  statistics: OnlineStatistics
  users?: OnlineUserInfo[]
  sessionDistribution?: SessionDistribution
}

// 在线统计信息
export interface OnlineStatistics {
  totalCount: number
  activeCount: number
  idleCount: number
  todayLoginCount: number
  averageOnlineMinutes: number
  statisticTime: string
}

// 在线用户信息
export interface OnlineUserInfo {
  userId: string
  username: string
  nickname?: string
  avatar?: string
  deptName?: string
  roleNames?: string[]
  sessionId: string
  loginIp?: string
  ipLocation?: string
  browser?: string
  os?: string
  deviceType?: string
  deviceInfo?: string
  userAgent?: string
  loginTime?: string
  lastActiveTime?: string
  onlineMinutes?: number
  remainingSeconds?: number
  isActive?: boolean
  loginType?: string
  tenantId?: string
}

// 会话分布统计
export interface SessionDistribution {
  deviceStats: DeviceStats
  browserStats: BrowserStats
  timeStats: TimeStats
}

// 设备统计
export interface DeviceStats {
  desktopCount: number
  mobileCount: number
  tabletCount: number
  unknownCount: number
}

// 浏览器统计
export interface BrowserStats {
  chromeCount: number
  firefoxCount: number
  safariCount: number
  edgeCount: number
  ieCount: number
  otherCount: number
}

// 时间分布统计
export interface TimeStats {
  morningCount: number    // 6:00-12:00
  afternoonCount: number  // 12:00-18:00
  eveningCount: number    // 18:00-24:00
  nightCount: number      // 0:00-6:00
}

// 系统监控
export interface SystemMonitor {
  cpu: {
    used: number
    total: number
    percentage: number
  }
  memory: {
    used: number
    total: number
    percentage: number
  }
  disk: {
    used: number
    total: number
    percentage: number
  }
  jvm: {
    used: number
    total: number
    percentage: number
    version: string
  }
}

// 统计信息
export interface SystemStats {
  userCount: number
  roleCount: number
  permissionCount: number
  menuCount: number
  onlineUserCount: number
  todayLoginCount: number
  totalLoginCount: number
}
